import { App } from 'antd';
import { createContext, useContext, useEffect, useRef } from 'react';

const MessageContext = createContext<any>(null);

export const MessageProvider = ({ children }: { children: React.ReactNode }) => {
  const { message } = App.useApp();
  const messageRef = useRef(message);

  useEffect(() => {
    messageRef.current = message;
  }, [message]);

  return (
    <MessageContext.Provider value={messageRef.current}>
      {children}
    </MessageContext.Provider>
  );
};

export const useMessage = () => {
  return useContext(MessageContext);
}; 